package net.chenlin.dp.modules.ticket.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import net.chenlin.dp.common.annotation.SysLog;
import net.chenlin.dp.modules.sys.controller.AbstractController;
import net.chenlin.dp.common.entity.Page;
import net.chenlin.dp.common.entity.R;
import net.chenlin.dp.modules.ticket.entity.TicketEntity;
import net.chenlin.dp.modules.ticket.service.TicketService;

/**
 * 
 * @author ZhouChenglin<yczclcn@163.com>
 */
@RestController
@RequestMapping("/ticket")
public class TicketController extends AbstractController {
	
	@Autowired
	private TicketService ticketService;
	
	/**
	 * 列表
	 * @param params
	 * @return
	 */
	@RequestMapping("/list")
	public Page<TicketEntity> list(@RequestBody Map<String, Object> params) {
		return ticketService.listTicket(params);
	}
		
	/**
	 * 新增
	 * @param ticket
	 * @return
	 */
	@SysLog("新增")
	@RequestMapping("/save")
	public R save(@RequestBody TicketEntity ticket) {
		return ticketService.saveTicket(ticket);
	}
	
	/**
	 * 根据id查询详情
	 * @param id
	 * @return
	 */
	@RequestMapping("/info")
	public R getById(@RequestBody Long id) {
		return ticketService.getTicketById(id);
	}
	
	/**
	 * 修改
	 * @param ticket
	 * @return
	 */
	@SysLog("修改")
	@RequestMapping("/update")
	public R update(@RequestBody TicketEntity ticket) {
		return ticketService.updateTicket(ticket);
	}
	
	/**
	 * 删除
	 * @param id
	 * @return
	 */
	@SysLog("删除")
	@RequestMapping("/remove")
	public R batchRemove(@RequestBody Long[] id) {
		return ticketService.batchRemove(id);
	}


	/**
	 * 根据id查询详情
	 * @param
	 * @return
	 */
	@RequestMapping("/test2")
	public R test() {
		return R.error("222111");
	}

	@ResponseBody
	@GetMapping("/all")
	public Object findAllTicket(
			@RequestParam(name = "pageNum", required = false, defaultValue = "1")
					int pageNum,
			@RequestParam(name = "pageSize", required = false, defaultValue = "10")
					int pageSize){
		return ticketService.findAllTicket(pageNum,pageSize);
	}

	/**
	 * 获取置顶门票信息
	 * @return
	 */
	@RequestMapping("/select")
	public R listRole(
    	        @RequestParam(name = "sortby", required = false, defaultValue = "scenic_score")
	        String sortby) {
		return ticketService.listTicket(sortby);
	}
}
